$(function () {
    $("#btnAgree").on("click",function(){
        alert("通过");
    });
    $("#btnReject").on("click",function(){
        alert("驳回");
    });
    $("#btnSave").on("click",function(){
        alert("保存");
    });
    $("#btnSubmit").on("click",function(){
        alert("提交");
    });
    $("#btnBack").on("click",function(){
        history.go(-1);
    });
})




















// 修改
$("#btnRevise").on("click",function(){
    $("#stakeTrace").hide();
    $("#addChargingGunBtn").show();
    $("#equipmentClick").prop("disabled",false);
    $("#stationClick").prop("disabled",false);
    var uuid = "";
    var equipmodeluuid = "";
    var parkingareauuid = "";
    var stationuuid = "";
    var p_n = $('#tb_ads').bootstrapTable('getData');
    if (p_n != null && p_n.length > 0) {
        var len = $('#tb_ads').bootstrapTable('getData').length;
        for (var i = 0; i < len; i++) {
            if ($('#tb_ads').bootstrapTable('getData')[i].check == true) {
                uuid = $('#tb_ads').bootstrapTable('getData')[i].uuid;
                equipmodeluuid = $('#tb_ads').bootstrapTable('getData')[i].equipmodeluuid;
                parkingareauuid = $('#tb_ads').bootstrapTable('getData')[i].parkingareauuid;
                stationuuid = $('#tb_ads').bootstrapTable('getData')[i].stationuuid;
            };
        };
        if (uuid != '' && uuid != null) {
            var index = layer.open({
                type: 1,
                title: "修改充电桩",
                shadeClose: true,
                shade: 0.3,
                area: ['100%', '90%'],
                skin: 'layui-layer-rims',
                content: $(".addStake"),
                closeBtn:1,
                shadeClose:false,
                fixed:false,
                resize:true,
                maxmin:true,
                btn:['确定','关闭'],
                success:function(){
                    getStakeTemplate(uuid);
                    getStationTemplate(stationuuid);
                    getEquipmentTemplate(equipmodeluuid);
                    getParkAreaTemplate(parkingareauuid);
                    getChargeGunTemplate(uuid);
                },
                yes:function(){
                    saveStake(uuid);
                    layer.close(index);
                },
                btn1:function () {
                },
                cancel:function(){
                }
            });
        } else {
            layerAlert.errorMessage("您的选择为空");
        }
    };
});
function saveStake(uuid){
    var stakeParams = {};
    stakeParams.baseStake = {};
    stakeParams.baseStake.stakeno = $("#stakeNos").val(); // 桩编号
    stakeParams.baseStake.stakename = $("#stakename").val(); // 桩名称
    stakeParams.baseStake.runtime = $("#runtime").val(); // 投运时间
    stakeParams.baseStake.authcode = $("#authcode").val(); // 授权码
    stakeParams.baseStake.registrationuuid = $("#registrationuuid").val(); // 注册码
    stakeParams.baseStake.createdat = $("#createdat").val(); // 生产日期
    stakeParams.baseStake.staketype = $("#stakeTypes").val(); // 桩类型
    stakeParams.baseStake.type = $("#typeinfo").val(); // 设备类型
    stakeParams.baseStake.debuggingtime = $("#debuggingtime").val(); // 调试时间
    stakeParams.baseStake.vendoruuid = $("#vendoruuid").attr("datauuid"); // 生产厂商uuid
    stakeParams.baseStake.equipmodeluuid = $("#equipmentno").attr("datauuid"); // 设备uuid
    stakeParams.baseStake.stationuuid = $("#stationnameInfo").attr("uuid"); // 充电站uuid
    stakeParams.baseStake.isthird = $("#isthird").val(); // 三方
    stakeParams.baseStake.parkingareauuid = $("#parkAreaNameInfo").attr("parkuuid"); // 区uuid
    stakeParams.baseStake.uuid = uuid; // 桩主键
    stakeParams.baseStake.status = $("#status").val(); // 桩标记

    //新建枪
    var charger = {};
    var tablist = nthTabs.getTabList();
    for (var i = 0;i<tablist.length;i++){
        charger.type = $(tablist[i].id+" select[name='type']").val(); // 设备接口类型
        charger.spaceuuid = $(tablist[i].id+" select[name='parkSpaceSelect']").val(); // 关联停车位
    };
    /*charger.parkingAreaUuid = $("#parkAreaNameInfo").attr("parkuuid"); // 区uuid
     charger.stakeNo = $("#stakeNos").val(); // 桩编号
     charger.stakeUuid  = uuid;
     charger.stationUuid = $("#stationnameInfo").attr("uuid"); // 充电站uuid*/

    // 新建位
    var parkingSpace = {};
    /*parkingSpace.parkingareauuid = $("#parkAreaNameInfo").attr("parkuuid"); // 区uuid
     parkingSpace.stationuuid = $("#stationnameInfo").attr("uuid"); // 站uuid*/
    parkingSpace.name = $("#newAddParkSpaceName").val(); // 新建关联停车位name

    var chargerList = {};
    if(charger.type != undefined || charger.spaceuuid != undefined){
        chargerList.charger=charger;
    }
    if(parkingSpace.name != undefined && parkingSpace.name !=""){
        chargerList.parkingSpace=parkingSpace;
    }
    stakeParams.chargers = chargerList;
    $.ajax({
        type: "POST",
        url:projectPath+'/base/stakes/update',
        dataType:"json",
        data:JSON.stringify(stakeParams),
        contentType:"application/json",
        success:function (data) {
            if(data.code == "0"){
                layerAlert.successMessage("修改成功","");
            }else{
                layerAlert.errorMessage("修改失败");
            }
        },
        error:function () {
            layerAlert.errorMessage("数据错误");
        }
    });
}
// 设备类型-接口标准关联查询
$("#typeinfo").on("change",function(){
    var vals = $("#typeinfo").val();
    if(vals == "1"){ // 直流
        getSelectOptionsWithCode({code:'30005052',selectid:'standard'});
    }else if(vals == "2"){ // 交流
        getSelectOptionsWithCode({code:'30005051',selectid:'standard'});
    }/*else{ // TODO 通用code不知
     getSelectOptionsWithCode({code:'30008002',selectid:'standard'});
     }*/
});


var nthTabs;
// 详情查看
function stake_detail(parkingareauuid,equipmodeluuid,stationuuid,stakeuuid){
    $("#uuid").val(stakeuuid);
    $(".stakeTrace").show();
    $("#addChargingGunBtn").hide();
    $("#equipmentClick").prop("disabled",true);
    $("#stationClick").prop("disabled",true);
    layer.open({
        type: 1,
        title: "充电桩详情",
        shadeClose: true,
        shade: 0.3,
        area: ['100%', '90%'],
        skin: 'layui-layer-rims',
        content: $(".addStake"),
        closeBtn:1,
        shadeClose:false,
        fixed:false,
        resize:true,
        maxmin:true,
        btn:['关闭'],
        success:function(){
            getStakeTemplate(stakeuuid);
            getStationTemplate(stationuuid);
            getEquipmentTemplate(equipmodeluuid);
            getParkAreaTemplate(parkingareauuid);
            getChargeGunTemplate(stakeuuid);
        }
    });
}


$(function(){
    // 操作轨迹
    $("#stakeTrace").click(function () {
        layer.open({
            type:1,
            title:"充电桩操作轨迹",
            shade:0.3,
            shadeClose: true,
            move :false,
            area: ['80%', '80%'],
            skin: 'layui-layer-rims',
            content:$("#traceDetail"),
            btn:['关闭'],
            fixed:false,
            resize:true,
            // maxmin:true,
            success:function(){
            }
        })
    });

    // 操作轨迹切换布局
    $('#leftVersion').click(function (event) {
        event.preventDefault()
        $('#vertical-timeline').toggleClass('center-orientation');
    });
    // 运营商
    listOperatorSelect({selectid:'operatoruuid'});




    var clickCount = 0;
    $("#addChargingGunBtn").click(function() {
        if(nthTabs == undefined || nthTabs == null){
            nthTabs = $("#editor-tabs").nthTabs();
        };
        if(nthTabs.getTabList().length >= 2){
            layerAlert.errorMessage("一桩只能绑定两个枪");
            return;
        };
        if(clickCount < 1){
            var uuid= "chargGunUuid" + Math.ceil(Math.random()*10); //uuid
            var addHtmlContent = '';
            addHtmlContent += '<div class="col-md-12" style="margin-top:20px;">';
            addHtmlContent += '<div class="col-md-12 form-group">';
            addHtmlContent += '<div class="col-md-4 col-sm-4 col-xs-4 "><label class="label-width1">充电枪编号:</label><input type="text" name="chargNo" class="form-control" readonly></div>';
            addHtmlContent += '<div class=" col-md-4 col-sm-4 col-xs-4 "><label class="label-width1">枪资产编码:</label><input type="text" name="assetNo" class="form-control" readonly></div>';
            addHtmlContent += '<div class=" col-md-4 col-sm-4 col-xs-4 "> <label class="label-width4">设备接口类型:</label><select class="form-control" name="type"><option value="">--请选择--</option><option value="1">家用插座</option><option value="2">交流接口插座</option><option value="3">交流接口插头</option><option value="4">直流接口枪头</option></select></div>';
            addHtmlContent += '</div><div class="col-md-12 form-group">';
            addHtmlContent += '<div class="col-md-4 col-sm-4 col-xs-4"><label class="label-width1">关联停车位:</label><select class="form-control" name="parkSpaceSelect" id="parkSpaceSelect" style="border-radius: 4px 0px 0px 4px;width: 58%;"><option value=></option></select><button id="addParkSpaceClick" class="btn" style="border-radius: 0px 4px 4px 0px;vertical-align: top;width: 12%;display: none"><i class="	fa fa-plus"></i></button></div>';
            addHtmlContent += '<div class="col-md-4 col-sm-4 col-xs-4 newAddParkSpaceDiv" style="display: none;"><label class="label-width1">新增停车位:</label><input type="text" class="form-control" id="newAddParkSpaceName"></div>';
            addHtmlContent += '</div></div>';
            nthTabs.addTab({
                id:uuid,
                title:"新增充电枪",
                content:addHtmlContent
            });
            nthTabs.setActTab(uuid);
            clickCount++;
        }else{
            layerAlert.errorMessage("一次只能新建一个枪");
        }
        // 添加充电枪对停车位的操作
        var tablist = nthTabs.getTabList();
        $.ajax({
            url: projectPath + '/base/parking/spaces/listByArea?parkingAreaUuid=' + $("#parkAreaNameInfo").attr("parkuuid"),
            type: 'POST',
            dataType: 'json',
            success:function (data) {
                var parkspaceList=data.data;
                if(parkspaceList.length >0){
                    $("#parkSpaceSelect").css("width","70%");
                    document.getElementById("parkSpaceSelect").style.borderRadius = "4px";
                    for (var i = 0;i<tablist.length;i++){
                        $(tablist[i].id+" select[name='parkSpaceSelect']").empty();
                        $(tablist[i].id+" select[name='parkSpaceSelect']").append("<option value=''>--请选择--</option>");
                        $.each(parkspaceList,function(index, item){
                            if(item.bindedCharger == "0"){
                                $(tablist[i].id+" select[name='parkSpaceSelect']").append("<option value='"+item.uuid+"'>"+item.name+"</option>");
                            }else if(item.bindedCharger == "1"){
                                $(tablist[i].id+" select[name='parkSpaceSelect']").append("<option value='"+item.uuid+"' title='该停车位已绑定，不可选择！' disabled>"+item.name+"</option>");
                            };
                        });
                    }
                }else{
                    $("#addParkSpaceClick").show().on("click",function(){
                        $(".newAddParkSpaceDiv").show();
                    });
                }

            },
            error:function () {
                layerAlert.errorMessage("出错了");
            }
        });
    });
});

/*详情，修改回显公共方法提炼*/
function getStakeTemplate(stakeuuid){
    // 桩信息回显
    $.ajax({
        type: "POST",
        url:projectPath+'/base/stakes/detail?id='+stakeuuid,
        async:false,
        dataType:"json",
        success:function (data) {
            result = data.data;
            $("#stakeNos").val(result.stakeno); // 桩编号
            $("#stakename").val(result.stakename); // 桩名称(字段中的别名)
            if(result.runtime == null){
                $("#runtime").val(""); // 投运时间
            }else{
                $("#runtime").val(getLocalTime(result.runtime)); // 投运时间
            };
            $("#authcode").val(result.authcode); // 授权码
            $("#registrationuuid").val(result.registrationuuid); // 注册码
            if(result.useAt == null){
                $("#registdat").val("");     // 注册时间
            }else{
                $("#registdat").val(getLocalTime(result.useAt));     // 注册时间
            };
            if(result.createdat == null){
                $("#createdat").val(""); // 生产时间
            }else{
                $("#createdat").val(getLocalTime(result.createdat)); // 生产时间
            };
            //$("#factoryno").val(result);                    // TODO 出厂编号
            $("#durableyears").val(result.durableYears); //使用年限
            $("#stakeTypes").val(result.staketype); // 桩类型(公专)
            $("#typeinfo").val(result.type); // 设备类型
            $("#status").val(result.status); // 桩标记

            if(result.type == "1"){ // 直流
                getSelectOptionsWithCode({code:'30005052',selectid:'standard'});
            }else if(result.type == "2"){ // 交流
                getSelectOptionsWithCode({code:'30005051',selectid:'standard'});
            }/*else{
             getSelectOptionsWithCode({code:'30008002',selectid:'standard'});
             }*/
            if(result.debuggingtime == null){
                $("#debuggingtime").val(""); // 调试时间
            }else{
                $("#debuggingtime").val(getLocalTime(result.debuggingtime)); // 调试时间
            };
        },
        error:function () {
            layerAlert.errorMessage("不好意思，数据出错啦！");
        }
    });
};

function getStationTemplate(stationuuid){
    // 站信息回显
    $.ajax({
        type: "GET",
        url:projectPath+'/base/stations/'+stationuuid,
        async:false,
        dataType:"json",
        success:function (data) {
            var result = data.data;
            $("#stationnameInfo").val(result.stationname); // 站名称
            $("#stationnameInfo").attr("uuid",result.uuid); // 站名称
            $("#standards").selectpicker('val',result.standard.split(",")); // 国标类型(充电标准)
            $('#standards').selectpicker('refresh');

            var tradetypes = result.tradetypes;
            var groupCheckbox=$("input[name='tradeTypes']");
            for(var i=0;i<groupCheckbox.length;i++){
                if(isInArray(tradetypes,groupCheckbox[i].value)){
                    groupCheckbox[i].checked=true;
                }
            }; // 交易类型
            $("#provinceCityPartInfo").val(result.partOrgName); // 组织机构
            $("#address").val(result.address); // 站地址
            $("#isthird").val(result.isthird); // 三方
            $("#stationType").selectpicker('val',((result.isthird==0||result.isthird==1)?"0":"1")+"-"+result.stationtype); // 站点类型
            $('#stationType').selectpicker('refresh');

            $("#lat").val(result.lat); // 经度
            $("#lng").val(result.lng); // 纬度
            $('#operatoruuid').selectpicker('val', result.operatoruuid);//运营商设置选中
            $('#operatoruuid').selectpicker('refresh');

            $("#servicephone").val(result.servicephone); // 服务电话
            $("#prorgCode").val(result.prOrgName); // 产权单位
        },
        error:function () {
            layerAlert.errorMessage("不好意思，数据出错啦！");
        }
    });
};

function getEquipmentTemplate(equipmodeluuid){
    // 设备型号信息回显
    $.ajax({
        type: "POST",
        url: projectPath + '/base/equipment/infos/detail?id=' + equipmodeluuid,
        async:false,
        dataType:"json",
        success:function (data) {
            result = data.data;
            if(result != null){
                $("#equipmentno").val(result.equipmentname); //设备型号
                $("#vendoruuid").val(result.vendorName); //生产厂商
                $("#vendoruuid").attr("datauuid",result.vendoruuid);
                $("#maxoutvolt").val(result.maxoutvolt); //最大电压
                $("#power").val(result.power); //额定功率
            }
        },
        error:function () {
            layerAlert.errorMessage("不好意思，数据出错啦！");
        }
    })
};

function getParkAreaTemplate(parkingareauuid){
    // 停车区信息回显
    $.ajax({
        type: "POST",
        url:projectPath+'/base/parking/areas/detail?id='+parkingareauuid,
        async:false,
        dataType:"json",
        success:function (data) {
            result = data.data;
            $("#parkAreaNameInfo").val(result.name);// 选择停车区
            $("#parkAreaNameInfo").attr("parkuuid",result.uuid); // 区uuid
            $("#parkingfee").val(result.parkingfee); // 收费标准
            $("#openat").val(result.openat); // 开放时间
            $("#closeat").val(result.closeat); //关闭时间
        },
        error:function () {
            layerAlert.errorMessage("不好意思，数据出错啦！");
        }
    });
};

function getChargeGunTemplate(stakeuuid){
    // 充电枪信息回显
    nthTabs = $("#editor-tabs").nthTabs({allowClose:false});
    $.ajax({
        type: "POST",
        url:projectPath+'/base/chargers/queryChargersByStakeUuid?stakeUuid='+stakeuuid,
        async:false,
        dataType:"json",
        success:function (data) {
            result = data.data;
            if (result){
                for(var i = 0, length1 = result.length; i < length1; i++){
                    var dataHtml = '';
                    dataHtml += '<div class="col-md-12" style="margin-top: 20px;">';
                    dataHtml += '<div class="col-md-12 form-group">';
                    dataHtml += '<div class="col-md-4 col-sm-4 col-xs-4 "><label class="label-width1">充电枪编号:</label><input type="text" disabled class="form-control" value="'+ result[i].chargerno +'"></div>';
                    dataHtml += '<div class=" col-md-4 col-sm-4 col-xs-4 "><label class="label-width1">枪资产编码:</label><input type="text" disabled class="form-control" value="'+ result[i].assetNo +'"></div>';
                    if(result[i].type =="1" ){
                        dataVal = "家用插座";
                    }else if(result[i].type == "2"){
                        dataVal = "交流接口插座";
                    }else if(result[i].type == "3"){
                        dataVal = "交流接口插头";
                    }else if(result[i].type == "4"){
                        dataVal = "直流接口枪头";
                    }else{
                        dataVal = "其他";
                    };
                    dataHtml += '<div class=" col-md-4 col-sm-4 col-xs-4 "> <label class="label-width4">设备接口类型:</label><input type="text" disabled class="form-control" value="'+ dataVal +'"></div>';
                    dataHtml += '</div><div class="col-md-12 form-group">';
                    dataHtml += '<div class="col-md-4 col-sm-4 col-xs-4"><label class="label-width1">关联停车位:</label><input type="text" disabled class="form-control" value="'+ result[i].parkingSpaceName +'"/></div>';
                    dataHtml += '</div></div>';
                    nthTabs.addTab({
                        id:result[i].uuid,
                        title:"充电枪" + i,
                        content:dataHtml
                    });
                    if(i == 0){
                        nthTabs.setActTab(result[i].uuid);
                    }
                };
            }
        },
        error:function () {
            layerAlert.errorMessage("不好意思，数据出错啦！");
        }
    });
};

//桩修改查询设备型号
$("#equipmentClick").on("click",function () {
    var index = layer.open({
        type: 1,
        title: "设备型号列表",
        shadeClose: true,
        shade: 0.3,
        area: ['90%', '90%'],
        skin: 'layui-layer-rims',
        content: $(".equipmentQuery"),
        closeBtn:1,
        shadeClose:false,
        fixed:false,
        resize:true,
        maxmin:true,
        btn:['确定','关闭'],
        success:function(){
        },
        yes:function(){
            var vendoruuid = "";
            var p_n = $('#equipment_table').bootstrapTable('getData');
            if (p_n != null && p_n.length > 0) {
                var len = $('#equipment_table').bootstrapTable('getData').length;
                for (var i = 0; i < len; i++) {
                    if ($('#equipment_table').bootstrapTable('getData')[i].check == true) {
                        vendoruuid = $('#equipment_table').bootstrapTable('getData')[i].vendoruuid; // 生产厂商uuid
                        vendorName = $('#equipment_table').bootstrapTable('getData')[i].vendorName; //  生产厂商
                        equipmodeluuid = $('#equipment_table').bootstrapTable('getData')[i].uuid; //  当前uuid
                        equipmentname = $('#equipment_table').bootstrapTable('getData')[i].equipmentname; // 设备型号
                        maxoutvolt = $('#equipment_table').bootstrapTable('getData')[i].maxoutvolt;
                        power = $('#equipment_table').bootstrapTable('getData')[i].power;
                    };
                };
                if (uuid != '' && uuid != null) {
                    $("#equipmentno").val(equipmentname);
                    $("#equipmentno").attr("datauuid",equipmodeluuid); // 设备型号 uuid
                    $("#vendoruuid").attr("datauuid",vendoruuid); //生产厂商 uuid
                    $("#vendoruuid").val(vendorName);
                    $("#maxoutvolt").val(maxoutvolt);
                    $("#power").val(power);
                } else {
                    layerAlert.errorMessage("您的选择为空");
                }
            };
            layer.close(index);
        },
        btn2:function(){
        },
        cancel:function () {
        }
    });
});
// 桩修改设备表格列表初始化
$('#equipment_table').bootstrapTable({
    method: 'GET',                      //请求方式（*）
    url:projectPath + "/base/equipment/infos/list",
    contentType: 'application/x-www-form-urlencoded',
    toolbar: '#toolbar',                //工具按钮用哪个容器
    striped: true,                      //是否显示行间隔色
    cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
    pagination: true,                   //是否显示分页（*）
    sortable: false,                     //是否启用排序
    sortOrder: "asc",                   //排序方式
    search:true,
    queryParams: queryEquipTabParams,//传递参数（*）
    sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
    pageNumber: 1,                       //初始化加载第一页，默认第一页
    pageSize: 10,                       //每页的记录行数（*）
    pageList: [10, 15,20],        //可供选择的每页的行数（*）
    strictSearch: true,
    clickToSelect: true,                //是否启用点击选中行
    uniqueId: "id",
    // showColumns: true,                  //是否显示所有的列
    // showRefresh: true,                  //显示刷新按钮
    // showToggle: true,
    minimumCountColumns: 12,             //最少允许的列数
    singleSelect:true,
    paginationPreText: "上一页",
    paginationNextText: "下一页",
    columns: [
        {field: 'check', checkbox: true},
        {field: '', title: '序号', align: 'center', formatter: function (value, row, index) {
            var pageSize=$('#equipment_table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
            var pageNumber=$('#equipment_table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
            return pageSize * (pageNumber - 1) + index + 1;    //返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
        }},
        {field: 'uuid', title: '主键', align: 'center', visible:false},
        {field: 'equipmentno', title: '型号编号', align: 'center',formatter:function (value, row, index) {
            return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'type', title: '型号类型',align: 'center',visible:false,formatter:function (value, row, index) {
            if(type == "1"){
                value = "直流类型";
            }else if(type == "2"){
                value ="交流类型";
            }else{
                value ="其他";
            }
            return '<div style="width:60px;min-width: 60px;max-width: 60px;margin: auto;">'+ value +'</div>';
        }},
        {field: 'power', title: '额定功率',align: 'center',formatter:function (value, row, index) {
            return "<div style='width:60px;min-width: 60px;max-width: 60px;margin: auto;'>" + value + "千瓦</div>";
        }},
        {field: 'minoutvolt', title: '最小输出电压',align: 'center',formatter:function (value, row, index) {
            if(value == "" || value == null){
                value = "";
            };
            return "<div style='width:100px;min-width: 100px;max-width: 100px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'maxoutvolt', title: '最大输出电压',align: 'center',formatter:function (value, row, index) {
            if(value == "" || value == null){
                value = "";
            };
            return "<div style='width:100px;min-width: 100px;max-width: 100px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'minoutcurrent', title: '最小输出电流', align: 'center',formatter:function (value, row, index) {
            if(value == "" || value == null){
                value = "";
            };
            return "<div style='width:100px;min-width: 100px;max-width: 100px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'maxoutcurrent', title: '最大输出电流',align: 'center',formatter:function (value, row, index) {
            if(value == "" || value == null){
                value = "";
            };
            return "<div style='width:100px;min-width: 100px;max-width: 100px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'vendorName', title: '生产厂商',align: 'center',formatter:function (value, row, index) {
            return "<div style='width:300px;min-width: 300px;max-width: 300px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'chargestandard', title: '充电标准',visible:false, align: 'center',visible:false,formatter:function (value, row, index) {
            if(value == "01"){
                value = "国标";
            }else if(value == "02"){
                value = "美标";
            }else if(value == "03"){
                value = "欧标";
            }else if(value == "04"){
                value = "国标2015";
            }else{
                value = "其他";
            };
            return "<div style='width:100px;min-width: 100px;max-width: 100px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'createdat', title: '创建时间',visible:false, align: 'center',visible:false,formatter:function (value, row, index) {
            if(value == "" || value == null){
                value="";
            }else{
                value = getLocalTime(value);
            }
            return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'updatedat', title: '修改时间',visible:false, align: 'center',visible:false,formatter:function (value, row, index) {
            if(value == "" || value == null){
                value="";
            }else{
                value = getLocalTime(value);
            }
            return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>" + value + "</div>";
        }}
    ],
    responseHandler: function (obj) {
        return {
            total:obj.data.total,
            rows:obj.data.list
        }
    }
});
function queryEquipTabParams() {
    var filter_equipment_table = {};
    filter_equipment_table.offset = (this.pageNumber-1)*this.pageSize;
    filter_equipment_table.limit = this.pageSize;
    return filter_equipment_table;
};

//桩修改查询站列表
$("#stationClick").on("click",function () {
    var index = layer.open({
        type: 1,
        title: "充电站列表",
        shadeClose: true,
        shade: 0.3,
        area: ['90%', '90%'],
        skin: 'layui-layer-rims',
        content: $(".stationQuery"),
        closeBtn:1,
        shadeClose:false,
        fixed:false,
        resize:true,
        maxmin:true,
        btn:['确定','关闭'],
        success:function(){
        },
        yes:function(){
            var uuid = "";
            var p_n = $('#station_table').bootstrapTable('getData');
            if (p_n != null && p_n.length > 0) {
                var len = $('#station_table').bootstrapTable('getData').length;
                for (var i = 0; i < len; i++) {
                    if ($('#station_table').bootstrapTable('getData')[i].check == true) {
                        uuid = $('#station_table').bootstrapTable('getData')[i].uuid; // 站uuid
                        stationname = $('#station_table').bootstrapTable('getData')[i].stationname; // 站名称
                        standard = $('#station_table').bootstrapTable('getData')[i].standard; // 国标类型(充电标准)
                        tradetypes = $('#station_table').bootstrapTable('getData')[i].tradetypes; // 交易类型
                        partOrgName = $('#station_table').bootstrapTable('getData')[i].partOrgName; // 省市部门
                        stationtype = $('#station_table').bootstrapTable('getData')[i].stationtype;
                        address = $('#station_table').bootstrapTable('getData')[i].address; // 站地址
                        isthird = $('#station_table').bootstrapTable('getData')[i].isthird; // 三方
                        lat = $('#station_table').bootstrapTable('getData')[i].lat;
                        lng = $('#station_table').bootstrapTable('getData')[i].lng;
                        operatoruuid = $('#station_table').bootstrapTable('getData')[i].operatoruuid; // 运营商
                        servicephone = $('#station_table').bootstrapTable('getData')[i].servicephone;
                        prOrgName = $('#station_table').bootstrapTable('getData')[i].prOrgName;
                    };
                };
                if (uuid != '' && uuid != null) {
                    $("#stationnameInfo").val(stationname); // 站名称
                    $("#stationnameInfo").attr("uuid",uuid); // 站uuid
                    $("#standards").selectpicker('val',standard.split(",")); // 国标类型(充电标准)
                    $('#standards').selectpicker('refresh');

                    // var tradetypes = result.tradetypes;
                    var groupCheckbox=$("input[name='tradeTypes']");
                    for(var i=0;i<groupCheckbox.length;i++){
                        if(isInArray(tradetypes,groupCheckbox[i].value)){
                            groupCheckbox[i].checked=true;
                        }
                    }; // 交易类型
                    $("#provinceCityPartInfo").val(partOrgName); // 组织机构
                    $("#address").val(address); // 站地址
                    $("#isthird").val(isthird); // 三方
                    $("#stationType").selectpicker('val',((isthird==0||isthird==1)?"0":"1")+"-"+ stationtype); // 站点类型
                    $('#stationType').selectpicker('refresh');

                    $("#lat").val(lat); // 经度
                    $("#lng").val(lng); // 纬度
                    $('#operatoruuid').selectpicker('val', operatoruuid);//运营商设置选中
                    $('#operatoruuid').selectpicker('refresh');

                    $("#servicephone").val(servicephone); // 服务电话
                    $("#prorgCode").val(prOrgName); // 产权单位
                } else {
                    layerAlert.errorMessage("您的选择为空");
                }
            };

            layer.close(index);
        },
        btn2:function(){

        },
        cancel:function () {

        }
    });
});
// 桩修改站表格列表初始化
$('#station_table').bootstrapTable({
    method: 'POST',                      //请求方式（*）
    url: projectPath+"/base/stations/list",
    contentType: 'application/x-www-form-urlencoded',
    toolbar: '#toolbar',                //工具按钮用哪个容器
    striped: true,                      //是否显示行间隔色
    cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
    pagination: true,                   //是否显示分页（*）
    sortable: false,                     //是否启用排序
    sortOrder: "asc",                   //排序方式
    search:true,
    queryParams: queryStationTabParams,//传递参数（*）
    sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
    pageNumber: 1,                       //初始化加载第一页，默认第一页
    pageSize: 10,                       //每页的记录行数（*）
    pageList: [10, 15,20],        //可供选择的每页的行数（*）
    strictSearch: true,
    clickToSelect: true,                //是否启用点击选中行
    uniqueId: "id",
    // showColumns: true,                  //是否显示所有的列
    // showRefresh: true,                  //显示刷新按钮
    // showToggle: true,
    minimumCountColumns: 12,             //最少允许的列数
    singleSelect:true,
    paginationPreText: "上一页",
    paginationNextText: "下一页",
    columns: [
        {field: 'check', checkbox: true},
        {field: '', title: '序号', align: 'center', formatter: function (value, row, index) {
            var pageSize=$('#station_table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
            var pageNumber=$('#station_table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
            return pageSize * (pageNumber - 1) + index + 1;    //返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
        }},
        {field: 'uuid', title: '主键', align: 'center', visible:false},
        {field: 'stationname', title: '充电站名称',align: 'center',formatter: function (value, row, index) {
            return '<div style="width:250px;min-width: 250px;max-width: 250px;margin: auto;">'+ value +'</div>';
        }},
        {field: 'stationno', title: '站编码',align: 'center',formatter: function (value, row, index) {
            return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'isthird', title: '是否第三方',align: 'center',formatter: function (value, row, index) {
            if(value == "0" || value == "1"){
                return "<div style='width:30px;min-width: 30px;max-width: 30px;margin: auto;'>否</div>";
            }else{
                return "<div style='width:30px;min-width: 30px;max-width: 30px;margin: auto;'>是</div>";
            };
        }},
        {field: 'lat', title: '经纬度',align: 'center',formatter: function (value, row, index) {
            return (row.lat+"/"+row.lng);
        }},
        {field: 'stationtype', title: '站类型',align: 'center',formatter:function(value, row, index){
            if(row.isthird == 0 || row.isthird == 1){
                switch(value){
                    //1高速,2城市公共,3单位内部,4公交,5其他,6出租车，99岸电
                    case 1:
                        value = "高速"
                        break;
                    case 2:
                        value ="城市公共"
                        break;
                    case 3:
                        value ="单位内部"
                        break;
                    case 4:
                        value ="公交"
                        break;
                    case 5:
                        value ="其他"
                        break;
                    case 6:
                        value ="出租车"
                        break;
                    case 99:
                        value ="岸电"
                        break;
                    default:value ="其他"
                }
            } else {
                switch(value){
                    //(1公共,50个人,100公交专用,101环卫专用,102物流专用,103出租车专用,255其他,99岸电)；
                    case 1:
                        value ="公共"
                        break;
                    case 50:
                        value ="个人"
                        break;
                    case 100:
                        value ="公交专用"
                        break;
                    case 101:
                        value ="环卫专用"
                        break;
                    case 102:
                        value ="物流"
                        break;
                    case 103:
                        value ="出租车"
                        break;
                    case 99:
                        value ="岸电"
                        break;
                    default:value ="其他"
                }
            }
            return "<div style='width:60px;min-width: 60px;max-width: 60px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'stationstatus', title: '站状态', align: 'center',formatter: function (value, row, index) {
            if(value == "2"){
                return "<div style='width:60px;min-width: 60px;max-width: 60px;margin: auto;'>待投运</div>";
            }else if(value == "3"){
                return "<div style='width:60px;min-width: 60px;max-width: 60px;margin: auto;'>运行</div>";
            }else if(value == "8"){
                return "<div style='width:60px;min-width: 60px;max-width: 60px;margin: auto;'>维护</div>";
            }else if(value == "10"){
                return "<div style='width:60px;min-width: 60px;max-width: 60px;margin: auto;'>停运</div>";
            }else if(value == "11"){
                return "<div style='width:60px;min-width: 60px;max-width: 60px;margin: auto;'>退运</div>";
            }else{
                return "";
            }
        }},
        {field: 'servicecode', title: '内外部', align: 'center',formatter: function (value, row, index) {
            if(row.urposetype==2){
                if(value==1){
                    return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>公用-对外开放</div>";
                } else {
                    return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>公用-对内开放</div>";
                }
            } else {
                return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>专用-不展示</div>";
            }
        }},
        {field: 'provinceName', title: '省份',align: 'center',visible:false,formatter: function (value, row, index) {
            return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'cityName', title: '城市',align: 'center',visible:false,formatter: function (value, row, index) {
            return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'provinceOrgName', title: '省组织机构',align: 'center',formatter: function (value, row, index) {
            return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'cityOrgName', title: '市组织机构', align: 'center',formatter: function (value, row, index) {
            return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'prOrgName', title: '产权单位', align: 'center',formatter: function (value, row, index) {
            return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'managerOrgName', title: '运维单位', align: 'center',formatter: function (value, row, index) {
            return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'rundate', title: '投运时间', align: 'center',visible:false,formatter: function (value, row, index) {
            if(value == "" || value == null){
                value="";
            }else{
                value = getLocalTime(value);
            };
            return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'createdat', title: '最近更新时间', align: 'center',sortable:true,order:'desc',visible:false,formatter: function (value, row, index) {
            if(row.updatedat != '' && row.updatedat != null){
                value = row.updatedat;
            }
            if(value == "" || value == null){
                value="";
            }else{
                value = getLocalTime(value);
            }
            return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>" + value + "</div>";
        }}
    ],
    responseHandler: function (obj) {
        return {
            total:obj.data.total,
            rows:obj.data.data
        }
    }
});
function queryStationTabParams() {
    var filterinfo = {};
    filterinfo.offset = (this.pageNumber-1)*this.pageSize;
    filterinfo.limit = this.pageSize;
    return filterinfo;
};

//桩修改查询 区列表
$("#parkAreaClick").on("click",function () {
    var index = layer.open({
        type: 1,
        title: "充电站列表",
        shadeClose: true,
        shade: 0.3,
        area: ['90%', '90%'],
        skin: 'layui-layer-rims',
        content: $(".parkAreaQuery"),
        closeBtn:1,
        shadeClose:false,
        fixed:false,
        resize:true,
        maxmin:true,
        btn:['确定','关闭'],
        success:function(){
        },
        yes:function(){
            var uuid= "";
            var p_n = $('#parkArea_table').bootstrapTable('getData');
            if (p_n != null && p_n.length > 0) {
                var len = $('#parkArea_table').bootstrapTable('getData').length;
                for (var i = 0; i < len; i++) {
                    if ($('#parkArea_table').bootstrapTable('getData')[i].check == true) {
                        uuid = $('#parkArea_table').bootstrapTable('getData')[i].uuid; // 区uuid
                        name = $('#parkArea_table').bootstrapTable('getData')[i].name; // 区名称
                        parkingfee = $('#parkArea_table').bootstrapTable('getData')[i].parkingfee; // 收费标准
                        openat = $('#parkArea_table').bootstrapTable('getData')[i].openat; // 开放
                        closeat = $('#parkArea_table').bootstrapTable('getData')[i].closeat; // 开放
                    };
                };
                if (uuid != '' && uuid != null) {
                    $("#parkAreaNameInfo").val(name);// 选择停车区
                    $("#parkAreaNameInfo").attr("parkuuid",uuid); // 区uuid
                    $("#parkingfee").val(parkingfee); // 收费标准
                    $("#openat").val(openat); // 开放时间
                    $("#closeat").val(closeat); //关闭时间
                } else {
                    layerAlert.errorMessage("您的选择为空");
                }
            };

            layer.close(index);
        },
        btn2:function(){

        },
        cancel:function () {

        }
    });
});
// 桩修改 停车区列表初始化
$('#parkArea_table').bootstrapTable({
    method: 'GET',                      //请求方式（*）
    url:projectPath+  "/base/parking/areas/list",//请求后台的URL（*）
    contentType: 'application/x-www-form-urlencoded',
    toolbar: '#toolbar',                //工具按钮用哪个容器
    striped: true,                      //是否显示行间隔色
    cache: true,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
    pagination: true,                   //是否显示分页（*）
    sortable: false,                     //是否启用排序
    sortOrder: "asc",                   //排序方式
    search:false,
    queryParams: queryParkAreaParams,//传递参数（*）
    sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
    pageNumber: 1,                       //初始化加载第一页，默认第一页
    pageSize: 10,                       //每页的记录行数（*）
    pageList: [3, 10,20],        //可供选择的每页的行数（*）
    strictSearch: true,
    clickToSelect: true,                //是否启用点击选中行
    uniqueId: "id",
    //showColumns: true,                  //是否显示所有的列
    //showRefresh: true,                  //显示刷新按钮
    //showToggle: true,
    minimumCountColumns: 6,             //最少允许的列数
    singleSelect:true,
    // height:500,
    paginationPreText: "上一页",
    paginationNextText: "下一页",
    columns: [
        {field: 'check', checkbox: true},
        {field: '', title: '序号', align: 'center', formatter: function (value, row, index) {
            var pageSize=$('#tb_ads').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
            var pageNumber=$('#tb_ads').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
            return pageSize * (pageNumber - 1) + index + 1;    //返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
        }},
        {field: 'uuid', title: '主键', align: 'center', visible:false},
        {field: 'name', title: '停车区名称', align: 'center',formatter: function (value, row, index) {
            return "<div style='min-width: 150px;margin: auto;'><a href='javascript:;' onclick='parkarea_detail(\""+row.uuid+"\")'>" + value + "</a></div>";
        }},
        {field: 'code', title: '停车区编码', align: 'center',formatter: function (value, row, index) {
            return "<div style='width:150px;min-width: 150px;max-width: 150px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'stationName', title: '所属站名称', align: 'center',formatter: function (value, row, index) {
            return "<div style='min-width: 120px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'stationAddress', title: '所属站地址', align: 'center',formatter: function (value, row, index) {
            return "<div style='min-width: 120px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'openat', title: '营业开始时间', align: 'center',formatter: function (value, row, index) {
            return "<div style='width:120px;min-width: 120px;max-width: 120px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'closeat', title: '营业关闭时间', align: 'center',formatter: function (value, row, index) {
            return "<div style='width:120px;min-width: 120px;max-width: 120px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'parkingfee', title: '收费标准', align: 'center',formatter: function (value, row, index) {
            return "<div style='width:120px;min-width: 120px;max-width: 120px;margin: auto;'>" + value + "</div>";
        }},
        {field: 'parkingdesc', title: '停车区描述', align: 'center',formatter: function (value, row, index) {
            return "<div style='width:120px;min-width: 120px;max-width: 120px;margin: auto;'>" + value + "</div>";
        }}
    ],
    responseHandler: function (obj) {
        return {
            total:obj.data.total,
            rows:obj.data.data
        }
    }
});
function queryParkAreaParams() {
    var filterinfo = {};
    filterinfo.offset = (this.pageNumber-1)*this.pageSize;
    filterinfo.limit = this.pageSize;
    return filterinfo;
};
